<?php

namespace app\admin\controller;

use app\admin\BaseController;
use app\admin\model\Notice;
use app\Request;
use think\db\Query;
use think\facade\Validate;
use app\admin\model\Opinion;

/* 
 * 意见反馈
 */
class OpinionController extends BaseController
{
    /*
     * 意见反馈
     * author xfwed
     * date 2023.03.10 15:39 
     * ------------------------------------------
     * update phper  2022-03-24 07:10 将token记入缓存
    */
    public function opinionList()
    {
        $all = input('param.');
        
        $perPage = input('param.perPage');
        $page = input('param.page');
        $content = input('param.content');//反馈内容
        $status = input('param.status');//1是2否已经处理	
       
        if($content){
            $map[] = ['o.content','like','%'.$content.'%'];
        }
        if($status){
            $where['o.status'] = $status;
        }
        $where = isset($where)?$where:[];
        $map = isset($map)?$map:[];
        $list = Opinion::alias('o')
                ->join('admin a','a.id = o.admin_id','left')
                ->where($where)
                ->where($map)
                ->field('o.*,a.realname')
                ->order('id desc')
                ->paginate($perPage);
        return $this->suc_json('查询成功',$list);
    }
    
    /*
     * 处理意见反馈
     * author xfwed
     * date 2023.03.10 15:43
     * ------------------------------------------
     * 
    */
    public function handleOpinion()
    {
        $all = input('param.');
        $validate = Validate::rule([
            'id|编号' => 'require',
            'deal_result|处理备注' => 'require',
        ]);
        if (!$validate->check($all)) {
            return $this->err_json($validate->getError());
        }
        $token = gT();
        $deal_name = $token['data']['realname'];
        $data['deal_name'] = $deal_name;
        $data['deal_time'] = gD();
        $data['deal_result'] = $all['deal_result'];
        $data['status'] = 1;
        $data['update_time'] = gD();
        $save = Opinion::where('id',$all['id'])->update($data);
        if($save){
            return $this->suc_json('处理成功');
        }  else {
            return $this->err_json('处理失败');
        }
       
    }
    



    

}